<template>
  <div class="home">
    <van-tabs v-model="active" @click="change">
      <van-tab
        v-for="item in fenlei"
        :key="item._id"
        :title="item.title"
        :name="item._id"
      >
      </van-tab>
    </van-tabs>
    <!-- vant横向导航  点击事件帮给父级 v-model的值就是当前点的tab的name值，就是分类id -->

    <div>
      <van-card
        v-for="item in res"
        :key="item._id"
        :price="item.price"
        :title="item.title"
        :thumb="item.pic"
      />
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fenlei: [],
      list: [],
      res: [],
      active: "",
    };
  },
  mounted() {
    this.$axios.get("fenlei.json").then((res) => {
      this.fenlei = res.data.result;
    });
    this.$axios.get("list.json").then((res) => {
      this.list = res.data.result;
      this.change();
    });
  },
  methods: {
    change() {
      this.res = this.list.filter((item) => {
        return item.cid == this.active;
      });
    },
  },
};
</script>
